var JVSlideShow5 = new Class({
	options:{},
	initialize:function(options){		
		this.setOptions(options);		
		this.jvSlide5Bg = $$(this.options.jvSlide5Bg);
		this.jvSlide5Menu = $$(this.options.jvSlide5Menu);	
		this.jvSlide5Info = $$(this.options.jvSlide5Info);	
		this.jvSlideMenuImg = $$(this.options.jvSlideMenuImg);
		this.jvSlide = $(this.options.jvSlide);		
		this.maxIter = this.jvSlide5Bg.length;				
		this.nextSlide = 0;					
		this.constructElement();
		this.jvSlide.removeClass('loading');	    
        this.jvSlide5Menu.each(function(item,i){
        	item.addEvent('click',function(event){
        		event = new Event(event);        		
        		event.stop();
        		this.changeSlideByClick(i);
        	}.bind(this));        	
        }.bind(this));         
        this.oldSlide = new Fx.Styles(this.jvSlide5Bg[0], {duration:this.options.durationSlide5});
        this.newSlide = new Fx.Styles(this.jvSlide5Bg[1], {duration:this.options.durationSlide5,transition: Fx.Transitions.linear});      
        this.info = new Fx.Style(this.jvSlide5Info[0],'opacity', {duration:300});
        this.info.start(1);
        this.jvSlideMenuImg[0].addClass('active');         
        this.changeSlide();
        this.slideTime = this.changeSlide.periodical(this.options.transaction,this);   				
	},
	constructElement:function(){		
	   this.jvSlide5Bg.each(function(item,i){	   
		   	item.setStyles('position:absolute;left:0;right:0');
		   	item.setStyle('opacity',0);
	   }.bind(this));
	   this.jvSlide5Info.each(function(item,i){
	   	    item.setStyle('opacity',0);
	   }.bind(this));
	   this.jvSlide5Bg[0].setStyle('opacity',1);
	   this.currInter = -1;	   
	},
	// Action fire when change slideshow
	changeSlide:function(){
		if(this.currInter != -1){
		this.jvSlideMenuImg.each(function(item,i){
			item.removeClass('active');
		}.bind(this));	
	   	if(this.currInter != this.jvSlide5Bg.length - 1) {
            this.activeSlide = this.currInter;
            this.nextSlide = this.currInter + 1;          
        } else { 
            this.activeSlide = this.currInter;
            this.nextSlide = 0;        
        }
       this.jvSlideMenuImg[this.nextSlide].addClass('active');                          
       this.oldSlide = new Fx.Styles(this.jvSlide5Bg[this.activeSlide], {duration:this.options.durationSlide5,transition: Fx.Transitions.linear});
       this.newSlide = new Fx.Styles(this.jvSlide5Bg[this.nextSlide], {duration:this.options.durationSlide5,transition: Fx.Transitions.linear});
       JVSlideShow5.Transitions[this.options.jvStyleEffect].pass([
                this.oldSlide,
                this.newSlide,
                this.activeSlide,
                this.nextSlide], this)();       
      if(this.currInter == this.jvSlide5Bg.length - 1) {this.currInter=0;} else { this.currInter++;}
    } else{
    	this.currInter = 0;
    }           
	},
	changeSlideByClick:function(num){	
     if(num!=this.currInter){     	   
     	  this.currInter = num; 		      
	      this.info.stop();
	      this.jvSlideMenuImg.each(function(item,i){
            item.removeClass('active');
          }.bind(this));
          this.jvSlideMenuImg[num].addClass('active');  	     	     	      
	      this.oldSlide = new Fx.Styles(this.jvSlide5Bg[this.nextSlide], {duration:this.options.durationSlide5,transition: Fx.Transitions.linear});
	      this.newSlide = new Fx.Styles(this.jvSlide5Bg[num], {duration:this.options.durationSlide5,transition: Fx.Transitions.linear});
          /*JVSlideShow5.Transitions["fadeslideleft"].pass([
            this.oldSlide,
            this.newSlide,
            this.nextSlide,
            num], this)();                
	      this.nextSlide = num;	 */
	      this.changeItem.delay(700,this,[this.oldSlide,this.newSlide,this.nextSlide,num]); 
	      $clear(this.slideTime);
          this.slideTime = this.changeSlide.periodical(this.options.transaction,this);              
     } 
	},		
	//End action change slide
	changeItem:function(oldSlide,newSlide,oldPos,newPos){
	    JVSlideShow5.Transitions[this.options.jvStyleEffect].pass([
           oldSlide,
           newSlide,
           oldPos,
           newPos], this)();  
           this.nextSlide = newPos;                    
    }
});
JVSlideShow5.implement(new Events);
JVSlideShow5.implement(new Options);

JVSlideShow5.Transitions = new Abstract ({
    fade: function(oldFx, newFx, oldPos, newPos){
    	this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        oldFx.options.duration = newFx.options.duration = this.options.fadeDuration;
        if (newPos > oldPos) newFx.start({opacity: 1});
        else
        {
            newFx.set({opacity: 1}).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
            oldFx.start({opacity: 0});
        }
    },
    crossfade: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        oldFx.options.duration = newFx.options.duration = this.options.fadeDuration;
        newFx.start({opacity: 1});
        oldFx.start({opacity: 0});
    },
    fadebg: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        oldFx.options.duration = newFx.options.duration = this.options.fadeDuration / 2;
        oldFx.start({opacity: 0}).chain(newFx.start.pass([{opacity: 1}], newFx));
    }
});
/**
 * @author jon
 */
JVSlideShow5.Transitions.extend({
    fadeslideleft: function(oldFx, newFx, oldPos, newPos){    	
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.Cubic.easeOut;
        oldFx.options.duration = newFx.options.duration = 1500;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        if (newPos > oldPos)
        {           	                
            newFx.start({
                left: [this.options.moduleWidth, 0],
                opacity: 1
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));
            oldFx.start({opacity: [1,0]});
        } else {
            newFx.start({opacity: [0,1]}).chain(function(){
            	this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));
            oldFx.start({
                left: [0, this.options.moduleWidth],
                opacity: 0
            }).chain(function(fx){fx.set({left: 0});}.pass(oldFx));
        }
    },
    fadeslideright: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.Cubic.easeOut;
        oldFx.options.duration = newFx.options.duration = 1500;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        if (newPos > oldPos)
        {
            newFx.start({opacity: [0,1]}).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
            oldFx.start({
                left: [0, this.options.moduleWidth],
                opacity: 0
            }).chain(function(fx){fx.set({left: 0});}.pass(oldFx));
        } else {
            newFx.start({
                left: [this.options.moduleWidth, 0],
                opacity: 1
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
            oldFx.start({opacity: [1,0]});
        }
    },
    continuoushorizontal: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));      
        if (
            ((newPos > oldPos) || ((newPos==0) && (oldPos == (this.maxIter-1) ))) &&
            (!((newPos == (this.maxIter-1 )) && (oldPos == 0)))
        ) {
            oldFx.set({opacity: 1});
            oldFx.start({
                left: [0, -644]
            });
            newFx.set({opacity: 1, left: 644});
            newFx.start({
                left: [644, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;;
        } else  {
            oldFx.set({opacity: 1});
            oldFx.start({
                left: [0, 644]
            });
            newFx.set({opacity: 1, left: -644});
            newFx.start({
                left: [-644, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;;
        }
    },
    continuoushorizontalright: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        if (
            ((newPos > oldPos) || ((newPos==0) && (oldPos == (this.maxIter-1) ))) &&
            (!((newPos == (this.maxIter-1 )) && (oldPos == 0)))
        ) {
            oldFx.set({opacity: 1});
            oldFx.start({
                left: [0, this.options.moduleWidth]
            });
            newFx.set({opacity: 1, left: this.options.moduleWidth * -1});
            newFx.start({
                left: [this.options.moduleWidth * -1, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        } else  {
            oldFx.set({opacity: 1});
            oldFx.start({
                left: [0, this.options.moduleWidth * -1]
            });
            newFx.set({opacity: 1, left: this.options.moduleWidth});
            newFx.start({
                left: [this.options.moduleWidth, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        }
    },
    continuousvertical: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        if (
            ((newPos > oldPos) || ((newPos==0) && (oldPos == (this.maxIter-1) ))) &&
            (!((newPos == (this.maxIter-1 )) && (oldPos == 0)))
        ) {
            oldFx.set({opacity: 1});
            oldFx.start({
                top: [0, this.options.moduleHeight * -1]
            });
            newFx.set({opacity: 1, top: this.options.moduleHeight});
            newFx.start({
                top: [this.options.moduleHeight, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        } else  {
            oldFx.set({opacity: 1});
            oldFx.start({
                top: [0, this.options.moduleHeight]
            });
            newFx.set({opacity: 1, top: this.options.moduleHeight * -1});
            newFx.start({
                top: [this.options.moduleHeight * -1, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        }
    },
    continuousverticalbuttom: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        if (
            ((newPos > oldPos) || ((newPos==0) && (oldPos == (this.maxIter-1) ))) &&
            (!((newPos == (this.maxIter-1 )) && (oldPos == 0)))
        ) {
            oldFx.set({opacity: 1});
            oldFx.start({
                top: [0, this.options.moduleHeight]
            });
            newFx.set({opacity: 1, top: this.options.moduleHeight * -1});
            newFx.start({
                top: [this.options.moduleHeight * -1, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        } else  {
            oldFx.set({opacity: 1});
            oldFx.start({
                top: [0, this.options.moduleHeight * -1]
            });
            newFx.set({opacity: 1, top: this.options.moduleHeight});
            newFx.start({
                top: [this.options.moduleHeight, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        }
    },
    jvslideshow: function(oldFx, newFx, oldPos, newPos){
        oldFx.options.transition = newFx.options.transition = Fx.Transitions.linear;
        this.jvSlide5Info.each(function(item,i){
                   this.jvSlide5Info[i].setStyle('opacity',0);  
        }.bind(this));
        //var jvheight = this.options.moduleHeight;
        //alert(this.options.moduleHeight);
        if (
            ((newPos > oldPos) || ((newPos==0) && (oldPos == (this.maxIter-1) ))) &&
            (!((newPos == (this.maxIter-1 )) && (oldPos == 0)))
        ) {
            oldFx.set({opacity: 1});
            oldFx.start({
                opacity: [1, 0],
                top: [0, this.options.moduleHeight]
            });
            newFx.set({
                opacity: 1,
                top: this.options.moduleHeight * -1
            });
            newFx.start({
                opacity: [0, 1],
                top: [this.options.moduleHeight, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        } else  {
            oldFx.set({opacity: 1});
            oldFx.start({
                opacity: [1, 0],
                top: [0, this.options.moduleHeight]
            });
            newFx.set({
                opacity: 1,
                top: this.options.moduleHeight
            });
            newFx.start({
                top: [this.options.moduleHeight, 0]
            }).chain(function(){
                this.info = new Fx.Style(this.jvSlide5Info[newPos],'opacity', {duration:300});
                this.info.start(1);
            }.bind(this));;
        }
    }
});
